<?php

namespace backend\models;

use Yii;
use common\components\HelpComponent;
/**
 * This is the model class for table "{{%user}}".
 *
 * @property integer $id
 * @property string $oppenid
 * @property integer $subscribe
 * @property string $nickname
 * @property integer $sex
 * @property string $city
 * @property string $country
 * @property string $province
 * @property string $headimgurl
 * @property integer $subscribe_time
 * @property string $remark
 * @property integer $groupid
 * @property string $unionid
 */
class User extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['oppenid'], 'required'],
            [['subscribe', 'sex', 'subscribe_time', 'groupid'], 'integer'],
            [['oppenid', 'nickname', 'city', 'country', 'province', 'remark', 'unionid'], 'string', 'max' => 50],
            [['headimgurl'], 'string', 'max' => 150],
            [['nickname'],'filterutf8'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'oppenid' => Yii::t('app', 'Oppenid'),
            'subscribe' => Yii::t('app', '是否关注'),
            'nickname' => Yii::t('app', '用户昵称'),
            'sex' => Yii::t('app', '性别(1=>男,2=>女,0=>未知)'),
            'city' => Yii::t('app', '城市'),
            'country' => Yii::t('app', '国家'),
            'province' => Yii::t('app', '省份'),
            'headimgurl' => Yii::t('app', '头像'),
            'subscribe_time' => Yii::t('app', '关注时间'),
            'remark' => Yii::t('app', '备注'),
            'groupid' => Yii::t('app', '分组'),
            'unionid' => Yii::t('app', '用户标示'),
        ];
    }

    public function filterutf8($attribute,$params){
        $this->nickname = HelpComponent::filterNoUtf8($this->nickname);
    }

    /**
     * @inheritdoc
     * @return UserQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new UserQuery(get_called_class());
    }
}
